<?php
/**
 * 列表选择
 * @author yupoxiong<i@yufuping.com>
 */

namespace generate\field;

class Select extends Field
{

    public static $html = <<<EOF
<div class="layui-form-item">
    <label for="[FIELD_NAME]" class="layui-form-label [REQUIRED]">[FORM_NAME]</label>
    <div class="layui-input-inline">
        <select name="[FIELD_NAME]" id="[FIELD_NAME]" lay-verify="[FORM_VALIDATE]" lay-search>
            <option value="">请选择[FORM_NAME]</option>
            [RELATION_DATA]
        </select>
    </div>
</div>\n
EOF;

    public static $rules = [
        'required' => '非空',
        'regular'  => '自定义正则'
    ];

    public static function create($data)
    {
        $html = self::$html;
        $html = str_replace(array('[FORM_NAME]', '[FIELD_NAME]', '[RELATION_DATA]', '[FORM_VALIDATE]', '[REQUIRED]'), array($data['form_name'], $data['field_name'] ?? '', $data['relation_data'] ?? '', self::$verify, self::$required), $html);
        return $html;
    }

}